# 导入必要的模块
from time import sleep  # 用于添加等待时间
from appium import webdriver  # Appium的Python客户端库
from appium.options.android import UiAutomator2Options  # Android UiAutomator2驱动选项
from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput
from selenium.webdriver.common.by import By

# 配置Appium连接选项
options = UiAutomator2Options()  # 创建UiAutomator2选项对象

# 设置基本设备能力(Desired Capabilities)
options.platform_name = "Android"  # 指定平台为Android
options.automation_name = "UiAutomator2"  # 使用UiAutomator2自动化引擎
options.device_name = "emulator-5554"  # 指定设备名称(adb devices获取)
# options.app_package = "com.android.settings"  # 要测试的App包名
# options.app_activity = ".Settings"  # 要启动的Activity名称
options.new_command_timeout = 300  # 新命令超时时间(秒)
options.udid = "emulator-5554"  # 明确指定设备UDID

# 初始化Appium WebDriver
# 参数1: Appium服务器地址(默认本地4723端口)
# 参数2: 配置选项
driver = webdriver.Remote(
    command_executor='http://127.0.0.1:4723',  # Appium服务器地址
    options=options  # 传入配置选项
)

# 连接成功提示
print("连接成功！")  # 打印连接成功信息



driver.find_element(By.XPATH,"//*[@text='智慧北网']").click()

# 等待3秒(模拟操作间隔)
sleep(3)  # 暂停3秒，确保应用完全启动

driver.find_element(By.XPATH,"//*[@text='我的']").click()
sleep(2)
driver.find_element(By.XPATH, "//*[@text='设置']").click()
sleep(2)
# driver.find_element(By.XPATH, "//*[@text='退出登录']").click()
# sleep(2)
driver.find_element(By.XPATH, "//*[@text='检查新版本']").click()
sleep(2)


# 关闭会话
driver.quit()  # 关闭驱动，结束测试会话
# quit()会关闭所有关联的窗口并终止WebDriver会话
# 与close()不同，quit()会完全退出浏览器驱动